package com.lsw.jgyf.ui.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.lsw.jgyf.R;
import com.lsw.jgyf.adapter.FragmentViewPagerAdapter;
import com.lsw.jgyf.inject.Constants;
import com.lsw.jgyf.ui.base.activity.TitleBarActivity;
import com.lsw.jgyf.ui.fragment.MyOrderFragment1;
import com.lsw.jgyf.ui.fragment.MyOrderFragment2;
import com.lsw.jgyf.ui.fragment.MyOrderFragment3;
import com.lsw.jgyf.ui.fragment.MyOrderFragment4;
import com.lsw.util.InputTools;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/7/12 0012.
 */

public class MyOrderActivity extends TitleBarActivity<MyOrderPresenter> implements MyOrderContract.View {
    @BindView(R.id.tabs)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.vp_view)
    ViewPager mViewPager;
    @BindView(R.id.et_seach)
    EditText et_seach;
    @BindView(R.id.ll_seach)
    LinearLayout ll_seach;
    private FragmentViewPagerAdapter viewPagerAdapter;
    private List<Fragment> fragments;

    private List<String> mTitleList = new ArrayList<>();//页卡标题集合
    //待付款
    private MyOrderFragment1 myOrderFragment1;
    //待收货
    private MyOrderFragment2 myOrderFragment2;
    //待评价
    private MyOrderFragment3 myOrderFragment3;
    //已完成
    private MyOrderFragment4 myOrderFragment4;

    @Override
    protected void initInjector() {
        mActivityComponent.inject(this);
    }

    @Override
    protected void initEventAndData() {
        myOrderFragment1 = new MyOrderFragment1();
        myOrderFragment2 = new MyOrderFragment2();
        myOrderFragment3 = new MyOrderFragment3();
        myOrderFragment4 = new MyOrderFragment4();
        mPresenter.getData();
        mTitleList.add("全部");
        mTitleList.add("待审核");
        mTitleList.add("已审核");
        mTitleList.add("拒绝");
        fragments = new ArrayList<>();
        fragments.add(myOrderFragment1);
        fragments.add(myOrderFragment2);
        fragments.add(myOrderFragment3);
        fragments.add(myOrderFragment4);
        viewPagerAdapter = new FragmentViewPagerAdapter(getSupportFragmentManager(), fragments, mTitleList);
        mViewPager.setAdapter(viewPagerAdapter);
        mTabLayout.setViewPager(mViewPager);//将TabLayout和ViewPager关联起来。
        //设置fragment不被回收
        mViewPager.setOffscreenPageLimit(4);
        et_seach.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    //TODO:你自己的业务逻辑
                    String seach = v.getText().toString().trim();
                    switch (mViewPager.getCurrentItem()) {
                        case 0:
                            myOrderFragment1.seach(seach);
                            break;
                        case 1:
                            myOrderFragment2.seach(seach);
                            break;
                        case 2:
                            myOrderFragment3.seach(seach);
                            break;
                        case 3:
                            myOrderFragment4.seach(seach);
                            break;
                    }
                }
                return false;
            }
        });
        ll_seach.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InputTools.ShowKeyboard(et_seach);
            }
        });
    }

    @Override
    protected int setContentLayoutView() {
        return R.layout.activity_my_order;
    }

    @Override
    public void setData() {

    }

    @Override
    protected void setActionBarDetail() {

    }
}
